Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
"this" keyword in an arrow function

I understood that the "this" keyword means the current execution context, or where the code was invoked. It may be the global object or an object that called it.

const nameObj = {
  name: "Jack",
logName: function(){
console.log(this.name)}
}
nameObj.logName() // Jack

It works fine for the regular functions, but for the arrow functions it returns the global object instead:

const nameObj = {
  name: "Jack",
logName: ()=> {
// console.log(this.name) would be undefined
console.log(this)
}
}
nameObj.logName() // The window object on the browser's console

Everything is clear till this point, however, I cannot understand when it comes to nesting an arrow function inside a regular function, the "this" keyword in the arrow function refers to the object that called it instead of the usual global or window object.

const nameObj = {
  name: "Jack",
  logName: function () {
    return () => console.log(this.name);
  },
};
const arrowLogName = nameObj.logName();
arrowLogName(); // Jack

Is the arrow function implicitly "capturing" the "this" value or something else I am missing?

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda